package com.lyc.controller;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lyc.api.*;
import com.lyc.constants.Constants;
import com.lyc.utils.HttpClient;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.*;

/**
 * @Auther: lyc
 * @Date: 2024/11/26 21:00
 */
public class HunpaiController {

    private static final Gson policyGson = new Gson();

    public static int bd_splash_to_reward; // 百度_开屏
    public static int bd_insert_to_reward; // 百度_插屏
    public static int bd_native_to_reward; // 百度_信息流

    public static int ks_splash_to_reward; // 快手_开屏
    public static int ks_insert_to_reward; // 快手_插屏
    public static int ks_native_to_reward; // 快手_信息流
    public static int ks_draw_to_reward; // 快手_draw信息流

    public static int ylh_splash_to_reward; // 优量汇_开屏
    public static int ylh_insert_to_reward; // 优量汇_插屏
    public static int ylh_native_to_reward; // 优量汇_信息流

    public static int KH_APP_ID;
    public static int KH_XXL_GGW_ID;
    public static int KH_HF_GGW_ID;
    public static int KH_JL_GGW_ID;

    static {
        loadProperties();
    }

    private static void loadProperties() {
        Properties props = new Properties();
        try (FileInputStream fis = new FileInputStream(new File(Constants.ACCOUNT_PATH + "account.properties"))) {
            props.load(fis);

            bd_splash_to_reward = Integer.parseInt(props.getProperty("bd_splash_to_reward"));
            bd_insert_to_reward = Integer.parseInt(props.getProperty("bd_insert_to_reward"));
            bd_native_to_reward = Integer.parseInt(props.getProperty("bd_native_to_reward"));

            ks_splash_to_reward = Integer.parseInt(props.getProperty("ks_splash_to_reward"));
            ks_insert_to_reward = Integer.parseInt(props.getProperty("ks_insert_to_reward"));
            ks_native_to_reward = Integer.parseInt(props.getProperty("ks_native_to_reward"));
            ks_draw_to_reward = Integer.parseInt(props.getProperty("ks_draw_to_reward"));

            ylh_splash_to_reward = Integer.parseInt(props.getProperty("ylh_splash_to_reward"));
            ylh_insert_to_reward = Integer.parseInt(props.getProperty("ylh_insert_to_reward"));
            ylh_native_to_reward = Integer.parseInt(props.getProperty("ylh_native_to_reward"));

            KH_APP_ID = Integer.parseInt(props.getProperty("KH_APP_ID"));
            KH_XXL_GGW_ID = Integer.parseInt(props.getProperty("KH_XXL_GGW_ID"));
            KH_HF_GGW_ID = Integer.parseInt(props.getProperty("KH_HF_GGW_ID"));
            KH_JL_GGW_ID = Integer.parseInt(props.getProperty("KH_JL_GGW_ID"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        // 穿山甲代码位
        // CsjApiClient.createCsjNativeAd(); // 信息流
        // CsjApiClient.createCsjBannerAd(); // 横幅
        // CsjApiClient.createCsjSplashAd(); // 开屏
        // CsjApiClient.createCsjRewardAd(); // 激励
        // CsjApiClient.createCsjDouDiRewardAd(); // 激励兜底
        // CsjApiClient.createCsjPreferredInsertAd(); // 插屏-优选
        // CsjApiClient.createCsjHalfScreenInsertAd(); // 插屏-半屏

        // 快手代码位
        // KsApiClient.createKsNativeAd(); // 信息流
        // KsApiClient.createKsRewardAd(); // 激励视频
        // KsApiClient.createKsInsertAd(); // 插屏
        // KsApiClient.createKsFullscreenAd(); // 全屏视频
        // KsApiClient.createKsDrawAd(); // draw视频
        // KsApiClient.createKsSplashAd(); // 开屏广告
        // KsApiClient.createKsNewInsertAd(); // 新插屏广告

        // 优量汇代码位
        // YlhApiClient.createYlhSplashAd(); // 开屏
        // YlhApiClient.createYlhRewardAd(); // 激励
        // YlhApiClient.createYlhHalfScreenInsertAd(); // 插屏-半屏
        // YlhApiClient.createYlhNativeAd(); // 信息流
        // YlhApiClient.createYlhBannerAd(); // 横幅

        // 百度代码位
        // BdApiClient.createBdSplashAd(); // 开屏
        // BdApiClient.createBdInsertAd(); // 插屏
        // BdApiClient.createBdNativeAd(); // 信息流
        // BdApiClient.createBdRewardAd(); // 激励
    }

    public static void start(boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws IOException, InterruptedException {
        // 创建Gromore混排广告位
        createGroHpRewardAdUnit("混排", isNeedYlh, isNeedKs, isNeedBd);
        Thread.sleep(1000);

        // // 创建Gromore开屏广告位
        // createGroHpSplashAdUnit("开屏", isNeedYlh, isNeedKs, isNeedBd);
        // Thread.sleep(1000);
        //
        // // 创建Gromore插屏广告位
        // createGroHpInsertAdUnit("插屏", isNeedYlh, isNeedKs, isNeedBd);
        // Thread.sleep(1000);
        //
        // // 创建Gromore信息流广告位
        // createGroHpNativeAdUnit("信息流", isNeedYlh, isNeedKs, isNeedBd);
        // Thread.sleep(1000);
        //
        // // 创建Gromore横幅广告位
        // createGroHpBannerAdUnit("横幅", isNeedYlh, isNeedKs, isNeedBd);
        // Thread.sleep(1000);

        // 创建代码位添加到自研混排广告位
        addCodeToKhRewardHpAdUnit(isNeedYlh, isNeedKs, isNeedBd);
        Thread.sleep(1000);

        // 创建代码位添加到自研信息流广告位
        addCodeToKhNativeAdUnit(isNeedYlh, isNeedKs, isNeedBd);
        Thread.sleep(1000);

        // 创建代码位添加到自研横幅广告位
        addCodeToKhBannerAdUnit(isNeedYlh);
        Thread.sleep(1000);
    }

    private static void createGroHpBannerAdUnit(String adUnitName, boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws InterruptedException {
        // gromore广告位
        Integer adUnitId = GromoreApiClient.createGromoreBannerAdUnit(adUnitName);
        Thread.sleep(1000);

        List<Map<String, Object>> csjAdSlotList = new ArrayList<>();

        // 穿山甲
        Integer adSlotId01 = CsjApiClient.createCsjBannerAd(); // 穿山甲横幅
        Thread.sleep(1000);
        Integer adSlotId02 = CsjApiClient.createCsjDouDiBannerAd(); // 穿山甲横幅兜底
        Thread.sleep(1000);

        csjAdSlotList.add(buildGroAdSlot(1, adSlotId01, null, 1, 0, 1, 1, 3));
        csjAdSlotList.add(buildGroAdSlot(0, adSlotId02, null, 1, 3, 1, 1, 3));

        GromoreApiClient.batchAdslot(103270010, csjAdSlotList);
        Thread.sleep(1000);

        // 优量汇
        if (isNeedYlh) {
            long adSlotId03 = YlhApiClient.createYlhBannerAd(); // 横幅
            Thread.sleep(1000);

            List<Map<String, Object>> ylhAdSlotList = new ArrayList<>();

            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId03, "ylh_横幅", 3, 0, 1, 1, 3));

            GromoreApiClient.batchAdslot(103270010, ylhAdSlotList);
            Thread.sleep(1000);
        }
    }

    private static void createGroHpInsertAdUnit(String adUnitName, boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws InterruptedException, IOException {
        // gromore广告位
        Integer adUnitId = GromoreApiClient.createGromoreInsertAdUnit(adUnitName);
        Thread.sleep(1000);

        List<Map<String, Object>> csjAdSlotList = new ArrayList<>();

        // 穿山甲
        Integer adSlotId01 = CsjApiClient.createCsjHalfScreenInsertAd(); // 穿山甲插屏
        Thread.sleep(1000);
        Integer adSlotId02 = CsjApiClient.createCsjDouDiHalfScreenInsertAd(); // 穿山甲插屏兜底
        Thread.sleep(1000);

        csjAdSlotList.add(buildGroAdSlot(1, adSlotId01, null, 1, 0, 1, 1, 0));
        csjAdSlotList.add(buildGroAdSlot(0, adSlotId02, null, 1, 3, 1, 1, 0));

        GromoreApiClient.batchAdslot(adUnitId, csjAdSlotList);
        Thread.sleep(1000);

        // 优量汇
        if (isNeedYlh) {
            long adSlotId03 = YlhApiClient.createYlhHalfScreenInsertAd(); // 插屏
            Thread.sleep(1000);

            List<Map<String, Object>> ylhAdSlotList = new ArrayList<>();

            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId03, "ylh_插屏", 3, 0, 1, 1, 1));

            GromoreApiClient.batchAdslot(adUnitId, ylhAdSlotList);
            Thread.sleep(1000);
        }

        // 快手
        if (isNeedKs) {
            long adSlotId08 = KsApiClient.createKsSplashAd(); // 插屏
            Thread.sleep(1000);

            List<Map<String, Object>> ksAdSlotList = new ArrayList<>();

            ksAdSlotList.add(buildGroAdSlot(2, adSlotId08, "ks_插屏", 7, 0, 1, 1, 1));

            GromoreApiClient.batchAdslot(adUnitId, ksAdSlotList);
            Thread.sleep(1000);
        }

        // 百度
        if (isNeedBd) {
            Integer adSlotId13 = BdApiClient.createBdSplashAd(); // 插屏
            Thread.sleep(1000);

            List<Map<String, Object>> bdAdSlotList = new ArrayList<>();

            bdAdSlotList.add(buildGroAdSlot(2, adSlotId13, "bd_插屏", 5, 0, 1, 1, 1));

            GromoreApiClient.batchAdslot(103269293, bdAdSlotList);
            Thread.sleep(1000);
        }
    }

    private static void createGroHpNativeAdUnit(String adUnitName, boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws InterruptedException, IOException {
        // gromore广告位
        Integer adUnitId = GromoreApiClient.createGromoreNativeAdUnit(adUnitName);
        Thread.sleep(1000);

        List<Map<String, Object>> csjAdSlotList = new ArrayList<>();

        // 穿山甲
        Integer adSlotId01 = CsjApiClient.createCsjNativeAd(); // 穿山甲信息流
        Thread.sleep(1000);
        Integer adSlotId02 = CsjApiClient.createCsjDouDiNativeAd(); // 穿山甲信息流兜底
        Thread.sleep(1000);

        csjAdSlotList.add(buildGroAdSlot(1, adSlotId01, null, 1, 0, 1, 1, 0));
        csjAdSlotList.add(buildGroAdSlot(0, adSlotId02, null, 1, 3, 1, 1, 0));

        GromoreApiClient.batchAdslot(adUnitId, csjAdSlotList);
        Thread.sleep(1000);

        // 优量汇
        if (isNeedYlh) {
            long adSlotId03 = YlhApiClient.createYlhRewardAd(); // 信息流
            Thread.sleep(1000);

            List<Map<String, Object>> ylhAdSlotList = new ArrayList<>();

            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId03, "ylh_信息流", 3, 0, 1, 1, 0));

            GromoreApiClient.batchAdslot(adUnitId, ylhAdSlotList);
            Thread.sleep(1000);
        }

        // 快手
        if (isNeedKs) {
            long adSlotId08 = KsApiClient.createKsSplashAd(); // 信息流
            Thread.sleep(1000);

            List<Map<String, Object>> ksAdSlotList = new ArrayList<>();

            ksAdSlotList.add(buildGroAdSlot(2, adSlotId08, "ks_信息流", 7, 0, 1, 1, 0));

            GromoreApiClient.batchAdslot(adUnitId, ksAdSlotList);
            Thread.sleep(1000);
        }

        // 百度
        if (isNeedBd) {
            Integer adSlotId13 = BdApiClient.createBdSplashAd(); // 信息流
            Thread.sleep(1000);

            List<Map<String, Object>> bdAdSlotList = new ArrayList<>();

            bdAdSlotList.add(buildGroAdSlot(2, adSlotId13, "bd_信息流", 5, 0, 1, 1, 0));

            GromoreApiClient.batchAdslot(adUnitId, bdAdSlotList);
            Thread.sleep(1000);
        }
    }

    private static void createGroHpSplashAdUnit(String adUnitName, boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws InterruptedException, IOException {
        // gromore广告位
        Integer adUnitId = GromoreApiClient.createGromoreSplashAdUnit(adUnitName);
        Thread.sleep(1000);

        List<Map<String, Object>> csjAdSlotList = new ArrayList<>();

        // 穿山甲
        Integer adSlotId01 = CsjApiClient.createCsjSplashAd(); // 穿山甲开屏
        Thread.sleep(1000);
        Integer adSlotId02 = CsjApiClient.createCsjDouDiSplashAd(); // 穿山甲开屏兜底
        Thread.sleep(1000);

        csjAdSlotList.add(buildGroAdSlot(1, adSlotId01, null, 1, 0, 1, 2, 0));
        csjAdSlotList.add(buildGroAdSlot(0, adSlotId02, null, 1, 3, 1, 2, 0));

        GromoreApiClient.batchAdslot(adUnitId, csjAdSlotList);
        Thread.sleep(1000);

        // 优量汇
        if (isNeedYlh) {
            long adSlotId03 = YlhApiClient.createYlhSplashAd(); // 开屏
            Thread.sleep(1000);

            List<Map<String, Object>> ylhAdSlotList = new ArrayList<>();

            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId03, "ylh_开屏", 3, 0, 1, 0, 0));

            GromoreApiClient.batchAdslot(adUnitId, ylhAdSlotList);
            Thread.sleep(1000);
        }

        // 快手
        if (isNeedKs) {
            long adSlotId04 = KsApiClient.createKsSplashAd(); // 开屏广告
            Thread.sleep(1000);

            List<Map<String, Object>> ksAdSlotList = new ArrayList<>();

            ksAdSlotList.add(buildGroAdSlot(2, adSlotId04, "ks_开屏", 7, 0, 1, 0, 0));

            GromoreApiClient.batchAdslot(adUnitId, ksAdSlotList);
            Thread.sleep(1000);
        }

        // 百度
        if (isNeedBd) {
            Integer adSlotId05 = BdApiClient.createBdSplashAd(); // 开屏
            Thread.sleep(1000);

            List<Map<String, Object>> bdAdSlotList = new ArrayList<>();

            bdAdSlotList.add(buildGroAdSlot(2, adSlotId05, "bd_开屏", 5, 0, 1, 0, 0));

            GromoreApiClient.batchAdslot(103268731, bdAdSlotList);
            Thread.sleep(1000);
        }
    }

    /**
     * 构建KH代码位
     *
     * @param name 广告位名称
     * @param daima 代码位ID
     * @param ecpm ecpm
     * @param pxSwitch 竞价开关
     * @param guanggaowangluoId 广告网络ID
     * @param guanggaoweiId 广告位ID
     * @param list 广告类型
     * @return 返回一个包含上述参数信息的Map对象
     */
    private static Map<String, Object> buildZyGgw(String name, long daima, int ecpm, int pxSwitch, int guanggaowangluoId, int guanggaoweiId, int list) {
        return new HashMap<String, Object>() {{
            put("name", name);
            put("daima", daima);
            put("ecpm", ecpm);
            put("px_switch", pxSwitch);
            put("app_id", KH_APP_ID);
            put("guanggaowangluo_id", guanggaowangluoId);
            put("guanggaowei_id", guanggaoweiId);
            put("list", list);
        }};
    }

    /**
     * 构建Gromore代码位
     *
     * @param biddingType 竞价类型
     * @param adSlotId 代码位ID
     * @param adSlotName 代码位名称
     * @param network 广告网络
     * @param sortType 排序方式，如果大于0则会被添加到结果中
     * @param status 状态
     * @param originType 渲染类型
     * @return 返回一个包含上述参数信息的Map对象
     */
    private static Map<String, Object> buildGroAdSlot(int biddingType, long adSlotId, String adSlotName, int network, int sortType, int status, int originType, int subAdType) {
        return new HashMap<String, Object>() {{
            put("bidding_type", biddingType);
            put("ad_slot_id", Long.toString(adSlotId));
            if (null != adSlotName) put("ad_slot_name", adSlotName);
            put("network", network);
            if (sortType > 0) put("sort_type", sortType);
            put("status", status);
            put("origin_type", originType);
            if (subAdType > 0) put("sub_ad_type", subAdType);
        }};
    }

    /**
     * 创建代码位添加到自研混排广告位
     */
    public static void addCodeToKhRewardHpAdUnit(boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws InterruptedException, IOException {
        List<Map<String, Object>> ggwList = new ArrayList<>();

        // 优量汇代码位
        if (isNeedYlh) {
            long daima1 = YlhApiClient.createYlhRewardAd(); // 激励
            Thread.sleep(1000);
            long daima2 = YlhApiClient.createYlhSplashAd(); // 开屏
            Thread.sleep(1000);
            long daima3 = YlhApiClient.createYlhHalfScreenInsertAd(); // 插屏-半屏
            Thread.sleep(1000);
            long daima4 = YlhApiClient.createYlhNativeAd(); // 信息流
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("优量汇_激励", daima1, 0, 1, 3, KH_JL_GGW_ID, 1));
            ggwList.add(buildZyGgw("优量汇_开屏_激励", daima2, 0, 1, 3, KH_JL_GGW_ID, 2));
            ggwList.add(buildZyGgw("优量汇_插屏_激励", daima3, 0, 1, 3, KH_JL_GGW_ID, 3));
            ggwList.add(buildZyGgw("优量汇_信息流_激励", daima4, 0, 1, 3, KH_JL_GGW_ID, 4));
        }

        // 快手代码位
        if (isNeedKs) {
            long daima5 = KsApiClient.createKsRewardAd(); // 激励视频
            Thread.sleep(1000);
            long daima6 = KsApiClient.createKsSplashAd(); // 开屏广告
            Thread.sleep(1000);
            long daima7 = KsApiClient.createKsNewInsertAd(); // 新插屏广告
            Thread.sleep(1000);
            long daima8 = KsApiClient.createKsNativeAd(); // 信息流
            Thread.sleep(1000);
            long daima9 = KsApiClient.createKsDrawAd(); // draw视频
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("快手_激励", daima5, 0, 1, 2, KH_JL_GGW_ID, 1));
            ggwList.add(buildZyGgw("快手_开屏_激励", daima6, 0, 1, 2, KH_JL_GGW_ID, 2));
            ggwList.add(buildZyGgw("快手_插屏_激励", daima7, 0, 1, 2, KH_JL_GGW_ID, 3));
            ggwList.add(buildZyGgw("快手_信息流_激励", daima8, 0, 1, 2, KH_JL_GGW_ID, 4));
            ggwList.add(buildZyGgw("快手_Draw信息流_激励", daima9, 0, 1, 2, KH_JL_GGW_ID, 6));
        }

        // 百度代码位
        if (isNeedBd) {
            Integer daima10 = BdApiClient.createBdRewardAd(); // 激励
            Thread.sleep(1000);
            Integer daima11 = BdApiClient.createBdSplashAd(); // 开屏
            Thread.sleep(1000);
            Integer daima12 = BdApiClient.createBdInsertAd(); // 插屏
            Thread.sleep(1000);
            Integer daima13 = BdApiClient.createBdNativeAd(); // 信息流
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("百度_激励", daima10, 0, 1, 4, KH_JL_GGW_ID, 1));
            ggwList.add(buildZyGgw("百度_开屏_激励", daima11, 0, 1, 4, KH_JL_GGW_ID, 2));
            ggwList.add(buildZyGgw("百度_插屏_激励", daima12, 0, 1, 4, KH_JL_GGW_ID, 3));
            ggwList.add(buildZyGgw("百度_信息流_激励", daima13, 0, 1, 4, KH_JL_GGW_ID, 4));
        }

        // 穿山甲代码位
        Integer daima14 = createGroRewardRvAdUnit(); // 创建Gromore激励竞价广告位
        Thread.sleep(1000);

        ggwList.add(buildZyGgw("穿山甲_激励", daima14, 0, 1, 1, KH_JL_GGW_ID, 1));

        // 设置请求头
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("Token", Constants.KH_TOKEN);

        ggwList.forEach(ggw -> {
            String response = HttpClient.doPost("http://juhe.kuhuan.club/api/juhe.guanggaoyuan/add_ggw", ggw, headers);
            System.out.println("response = " + response);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 创建代码位添加到自研横幅广告位
     */
    public static void addCodeToKhBannerAdUnit(boolean isNeedYlh) throws InterruptedException {
        if (isNeedYlh) {
            List<Map<String, Object>> ggwList = new ArrayList<>();

            // 优量汇
            long daima1 = YlhApiClient.createYlhBannerAd(); // 横幅
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("优量汇_横幅", daima1, 0, 1, 3, KH_HF_GGW_ID, 5));

            // 设置请求头
            Map<String, String> headers = new HashMap<>();
            headers.put("Content-Type", "application/json");
            headers.put("Token", Constants.KH_TOKEN);

            ggwList.forEach(ggw -> {
                String response = HttpClient.doPost("http://juhe.kuhuan.club/api/juhe.guanggaoyuan/add_ggw", ggw, headers);
                System.out.println("response = " + response);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
        }
    }

    /**
     * 创建代码位添加到自研信息流广告位
     */
    public static void addCodeToKhNativeAdUnit(boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws IOException, InterruptedException {
        List<Map<String, Object>> ggwList = new ArrayList<>();

        // 优量汇
        if (isNeedYlh) {
            long daima1 = YlhApiClient.createYlhNativeAd(); // 信息流
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("优量汇_信息流", daima1, 0, 1, 3, KH_XXL_GGW_ID, 4));
        }

        // 快手
        if (isNeedKs) {
            long daima2 = KsApiClient.createKsNativeAd(); // 信息流
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("快手_信息流", daima2, 0, 1, 2, KH_XXL_GGW_ID, 4));
        }

        // 百度
        if (isNeedBd) {
            Integer daima3 = BdApiClient.createBdNativeAd(); // 信息流
            Thread.sleep(1000);

            ggwList.add(buildZyGgw("百度_信息流", daima3, 0, 1, 4, KH_XXL_GGW_ID, 4));
        }

        // 设置请求头
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        headers.put("Token", Constants.KH_TOKEN);

        ggwList.forEach(ggw -> {
            String response = HttpClient.doPost("http://juhe.kuhuan.club/api/juhe.guanggaoyuan/add_ggw", ggw, headers);
            System.out.println("response = " + response);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
    }

    /**
     * 创建Gromore混排广告位
     */
    public static void createGroHpRewardAdUnit(String adUnitName, boolean isNeedYlh, boolean isNeedKs, boolean isNeedBd) throws IOException, InterruptedException {
        // gromore广告位
        Integer adUnitId = GromoreApiClient.createGromoreRewardRvAdUnit(adUnitName);
        Thread.sleep(1000);

        List<Map<String, Object>> csjAdSlotList = new ArrayList<>();

        // 穿山甲
        Integer adSlotId01 = CsjApiClient.createCsjRewardAd(); // 穿山甲激励
        Thread.sleep(1000);
        Integer adSlotId02 = CsjApiClient.createCsjDouDiRewardAd(); // 穿山甲激励兜底
        Thread.sleep(1000);

        csjAdSlotList.add(buildGroAdSlot(1, adSlotId01, null, 1, 0, 1, 1, 0));
        csjAdSlotList.add(buildGroAdSlot(0, adSlotId02, null, 1, 3, 1, 1, 0));

        GromoreApiClient.batchAdslot(adUnitId, csjAdSlotList);
        Thread.sleep(1000);

        // 优量汇
        if (isNeedYlh) {
            long adSlotId03 = YlhApiClient.createYlhRewardAd(); // 激励
            Thread.sleep(1000);
            long adSlotId04 = YlhApiClient.createYlhSplashAd(); // 开屏
            Thread.sleep(1000);
            long adSlotId05 = YlhApiClient.createYlhHalfScreenInsertAd(); // 插屏-半屏
            Thread.sleep(1000);
            long adSlotId06 = YlhApiClient.createYlhNativeAd(); // 信息流
            Thread.sleep(1000);

            List<Map<String, Object>> ylhAdSlotList = new ArrayList<>();

            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId03, "ylh_激励", 3, 0, 1, 1, 0));
            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId04, "ylh_开屏_激励", ylh_splash_to_reward, 0, 1, 0, 0));
            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId05, "ylh_插屏_激励", ylh_insert_to_reward, 0, 1, 0, 0));
            ylhAdSlotList.add(buildGroAdSlot(2, adSlotId06, "ylh_信息流_激励", ylh_native_to_reward, 0, 1, 0, 0));

            GromoreApiClient.batchAdslot(adUnitId, ylhAdSlotList);
            Thread.sleep(1000);
        }

        // 快手
        if (isNeedKs) {
            long adSlotId07 = KsApiClient.createKsRewardAd(); // 激励视频
            Thread.sleep(1000);
            long adSlotId08 = KsApiClient.createKsSplashAd(); // 开屏广告
            Thread.sleep(1000);
            long adSlotId09 = KsApiClient.createKsNewInsertAd(); // 新插屏广告
            Thread.sleep(1000);
            long adSlotId10 = KsApiClient.createKsNativeAd(); // 信息流
            Thread.sleep(1000);
            long adSlotId11 = KsApiClient.createKsDrawAd(); // draw视频
            Thread.sleep(1000);

            List<Map<String, Object>> ksAdSlotList = new ArrayList<>();

            ksAdSlotList.add(buildGroAdSlot(2, adSlotId07, "ks_激励", 7, 0, 1, 0, 0));
            ksAdSlotList.add(buildGroAdSlot(2, adSlotId08, "ks_开屏_激励", ks_splash_to_reward, 0, 1, 0, 0));
            ksAdSlotList.add(buildGroAdSlot(2, adSlotId09, "ks_插屏_激励", ks_insert_to_reward, 0, 1, 0, 0));
            ksAdSlotList.add(buildGroAdSlot(2, adSlotId10, "ks_信息流_激励", ks_native_to_reward, 0, 1, 0, 0));
            ksAdSlotList.add(buildGroAdSlot(2, adSlotId11, "ks_draw信息流_激励", ks_draw_to_reward, 0, 1, 0, 0));

            GromoreApiClient.batchAdslot(adUnitId, ksAdSlotList);
            Thread.sleep(1000);
        }

        // 百度
        if (isNeedBd) {
            Integer adSlotId12 = BdApiClient.createBdRewardAd(); // 激励
            Thread.sleep(1000);
            Integer adSlotId13 = BdApiClient.createBdSplashAd(); // 开屏
            Thread.sleep(1000);
            Integer adSlotId14 = BdApiClient.createBdInsertAd(); // 插屏
            Thread.sleep(1000);
            Integer adSlotId15 = BdApiClient.createBdNativeAd(); // 信息流
            Thread.sleep(1000);

            List<Map<String, Object>> bdAdSlotList = new ArrayList<>();

            bdAdSlotList.add(buildGroAdSlot(2, adSlotId12, "bd_激励", 5, 0, 1, 0, 0));
            bdAdSlotList.add(buildGroAdSlot(2, adSlotId13, "bd_开屏_激励", bd_splash_to_reward, 0, 1, 0, 0));
            bdAdSlotList.add(buildGroAdSlot(2, adSlotId14, "bd_插屏_激励", bd_insert_to_reward, 0, 1, 0, 0));
            bdAdSlotList.add(buildGroAdSlot(2, adSlotId15, "bd_信息流_激励", bd_native_to_reward, 0, 1, 0, 0));

            GromoreApiClient.batchAdslot(adUnitId, bdAdSlotList);
            Thread.sleep(1000);
        }

        // // 添加代码位到广告位
        // String response = GromoreApiClient.batchAdslot(adUnitId, adSlotList);
        // Thread.sleep(1000);
        //
        // // 解析响应
        // Type responseType = new TypeToken<Map<String, Object>>() {}.getType();
        // Map<String, Object> responseMap = policyGson.fromJson(response, responseType);
        //
        // String code = (String) responseMap.get("code");
        // String message = (String) responseMap.get("message");
        //
        // if ("100".equals(code) && "Success".equalsIgnoreCase(message)) {
        //     System.out.println("创建穿山甲混排广告位成功");
        // }
    }

    /**
     * 创建Gromore激励竞价广告位
     */
    public static Integer createGroRewardRvAdUnit() throws InterruptedException {
        // gromore广告位
        Integer adUnitId = GromoreApiClient.createGromoreRewardRvAdUnit("激励竞价");
        Thread.sleep(1000);

        // 穿山甲代码位
        Integer adSlotId1 = CsjApiClient.createCsjRewardAd(); // 激励
        Thread.sleep(1000);
        Integer adSlotId2 = CsjApiClient.createCsjDouDiRewardAd(); // 激励兜底
        Thread.sleep(1000);

        List<Map<String, Object>> adSlotList = new ArrayList<>();

        adSlotList.add(buildGroAdSlot(1, adSlotId1, "csj_激励", 1, 0, 1, 1, 0));
        adSlotList.add(buildGroAdSlot(0, adSlotId2, "csj_激励_兜底", 1, 3, 1, 1, 0));

        // 添加代码位到广告位
        String response = GromoreApiClient.batchAdslot(adUnitId, adSlotList);
        Thread.sleep(1000);

        // 解析响应
        Type responseType = new TypeToken<Map<String, Object>>() {}.getType();
        Map<String, Object> responseMap = policyGson.fromJson(response, responseType);

        String code = (String) responseMap.get("code");
        String message = (String) responseMap.get("message");

        if ("100".equals(code) && "Success".equalsIgnoreCase(message)) {
            return adUnitId;
        } else {
            return -1;
        }
    }
}
